package com.example.demo3.others;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();

        User user = new User();
        user.setName("zhangsang");
        user.setAge(18);
        user.setGender("male");

        //对象转字符串
        String s = objectMapper.writeValueAsString(user);
        System.out.println(s);
        //字符串转对象
        User user1 = objectMapper.readValue(s,User.class);
        System.out.println(user1);
    }
}
